﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:local="clr-namespace:Tisbi.LawFirm.UI.Views.Controls" xmlns:Views="clr-namespace:Tisbi.LawFirm.UI.Views" x:Class="Tisbi.LawFirm.UI.Views.Controls.CasesListView"
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="800">
    <Grid>
        <Grid.DataContext>
            <Binding Path="CaseViewModel" Source="{StaticResource Locator}"/>
        </Grid.DataContext>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.5*" />
            <ColumnDefinition Width="0.5*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="35"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50" MaxWidth="50"/>
                <ColumnDefinition Width="50" MaxWidth="50"/>
                <ColumnDefinition Width="50" MaxWidth="50"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition />
                <RowDefinition />
            </Grid.RowDefinitions>

            <mui:ModernButton Command="{Binding CreateCommand}" IsEnabled="{Binding CanAdd}" Grid.Row="0" Grid.Column="0" EllipseDiameter="32" HorizontalAlignment="Left" EllipseStrokeThickness="2" IconWidth="20" IconHeight="20" ToolTip="Добавить новое дело" IconData="{StaticResource AddIconData}" Width="34" />
            <mui:ModernButton Command="{Binding EditCommand}" IsEnabled="{Binding CanEdit}" Grid.Row="0" Grid.Column="1" EllipseDiameter="32" HorizontalAlignment="Left" EllipseStrokeThickness="2" IconWidth="20" IconHeight="20" ToolTip="Редактировать дело" IconData="{StaticResource EditIconData}" Width="34" />
            <mui:ModernButton Command="{Binding RemoveCommand}" IsEnabled="{Binding CanRemove}" Grid.Row="0"  Grid.Column="2" EllipseDiameter="32" HorizontalAlignment="Left" EllipseStrokeThickness="2" IconWidth="20" IconHeight="20" ToolTip="Удалить дело" IconData="{StaticResource RemoveIconData}" Width="34" />
            <mui:ModernButton Command="{Binding ArchiveCommand}" IsEnabled="{Binding CanArchive}" Grid.Row="0" Grid.Column="3" EllipseDiameter="32" HorizontalAlignment="Left" EllipseStrokeThickness="2" IconWidth="20" IconHeight="20" ToolTip="Поместить дело в архив" IconData="{StaticResource ArchiveIconData}" Width="34" />
            <mui:BBCodeBlock Visibility="{Binding HasVarnings}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="4" Foreground="Red" Margin="5" BBCode="{Binding Varnings}" />
        </Grid>

        <Grid Grid.Row="1" Grid.ColumnSpan="2" Grid.Column="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="220"/>
                <ColumnDefinition Width="50"/>
                <ColumnDefinition Width="220"/>
                <ColumnDefinition Width="110"/>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <!--Верхняя панель-->
            <ComboBox Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Employeeses}"
				SelectedItem="{Binding SelectedEmployees, Mode=TwoWay}"
				DisplayMemberPath="ShortFio"/>
            <Label Grid.Row="0" Grid.Column="1" Content="Поиск" HorizontalAlignment="Left" />
            <TextBox Text="{Binding SearchCriteria}" Grid.Row="0" Grid.Column="2" />
            <Button Content="Найти" Command="{Binding Search}" Grid.Row="0" Grid.Column="3" Margin="5,5,0,5" HorizontalAlignment="Left" Width="100"/>
        </Grid>

        <!--Таблица-->
        <DataGrid Grid.Row="2" Grid.Column="0" AutoGenerateColumns="False" IsReadOnly="True"
			ItemsSource="{Binding Model}"
			SelectedItem="{Binding SelectedModelItem, Mode=TwoWay}">
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding Id}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="№" />
                <DataGridTextColumn Binding="{Binding Title}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Название дела" />
                <DataGridTextColumn Binding="{Binding Employees.FullFio}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Юрист" />
                <DataGridTextColumn Binding="{Binding Created}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Дата создания" />
                <DataGridTextColumn Binding="{Binding Lawsuitses.Count}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Кол-во исков" />
            </DataGrid.Columns>
            <!--При выборе строки таблицы будет разворачиваться информация по делу-->
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <TabControl Margin="5">
                        <TabItem Header="Исковые заявления">
                            <local:LawsuitGreed DataContext="Lawsuitses" VerticalAlignment="Top" />
                            
                        </TabItem>

                        <TabItem Header="Претензии">
                            <local:ClaimsGreed VerticalAlignment="Top"/>
                        </TabItem>
                    </TabControl>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
        </DataGrid>
        <StackPanel Grid.Row="2" Grid.Column="1" VerticalAlignment="Top" Orientation="Vertical">
            <StackPanel.Resources>
                <Style TargetType="StackPanel">
                    <Setter Property="Orientation" Value="Horizontal" />
                    <Setter Property="Margin" Value="0,0,0,4" />
                </Style>
            </StackPanel.Resources>
            <StackPanel>
                <Label FontWeight="Bold" Width="200" FontSize="18">Судебные заседания:</Label>
            </StackPanel>
            <StackPanel>
                <DataGrid ItemsSource="{Binding Meetings}" Margin="10 0 0 0" AutoGenerateColumns="False" IsReadOnly="True" >
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding DateTimeOf}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Дата" />
                        <DataGridTextColumn Binding="{Binding Lawsuits.Number}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Рег. № иска" />
                        <DataGridTextColumn Binding="{Binding Court.Title}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" Header="Место" />
                    </DataGrid.Columns>
                </DataGrid>
            </StackPanel>
        </StackPanel>
    </Grid>
</UserControl>
